1
プロンプトエンジニアリング:生成型AIの主要インターフェース
AI011Lesson 2
00:00

プロンプトエンジニアリングの基礎

プロンプトエンジニアリング(PE) 大規模言語モデル(LLM)が高品質かつ一貫した結果を導くように、テキスト入力を設計・最適化するプロセスです。

1. インターフェースの定義

何であるか: 生成型AIの主要な「プログラミング」インターフェースとして機能します。
なぜか: 無作為で予測不可能なテキスト予測から、意図的で構造的な指示実行へとインタラクションを移行します。

2. モデルの基盤

  • ベースモデル(LLM): 膨大なデータセット内の統計的関係に基づいて次のトークンを予測するように単純に訓練され、確率 $P(w_t | w_1, w_2, ..., w_{t-1})$ を最大化します。
  • インストラクションチューニング済みのLLM: 人間のフィードバックによる強化学習(RLHF)により微調整され、特定の指示に明確に従い、役立つアシスタントとして動作するようにしています。

3. 効果的なプロンプトの構成要素

どのように: 効果的なプロンプトは通常、以下の要素を含みます:

  • 指示: 必要な具体的なアクション。
  • 主となるコンテンツ: 処理対象のターゲットデータ。
  • 補助的な内容: パラメータ、フォーマット、制約(確率的変動や幻覚を回避するため)。
トークン化の現実
モデルは単語を読み取るのではなく、 トークン——統計的確率を計算するために使用される、より小さなテキストの単位。
prompt_structure.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
What is the primary difference between a Base LLM and an Instruction-Tuned LLM?
Base LLMs only process code, while Instruction-Tuned LLMs process natural language.
Instruction-Tuned models are refined through human feedback to follow specific directions, whereas Base LLMs focus on statistical token prediction.
Base LLMs use tokens, but Instruction-Tuned LLMs read whole words at a time.
There is no difference; they are two terms for the exact same architecture.
Question 2
Why is the use of delimiters (like triple backticks or hashes) considered a best practice in prompt engineering?
They reduce the token count, making the API call cheaper.
They force the model to output in JSON format.
To separate instructions from the content the model needs to process, preventing 'separation of concerns' issues.
They increase the model's temperature setting automatically.
Challenge: Tutor AI Constraints
Refining prompts for educational safety.
You are building a tutor-style AI for a startup. The model is currently giving away answers too quickly and sometimes making up facts when it doesn't know the answer.
AI Tutor Interface
Task 1
Implement "Chain-of-thought" prompting in the system message to prevent the AI from giving away answers immediately.
Solution:
Instruct the model to: "Work through the problem step-by-step before providing the final answer. Do not reveal the final answer until the student has attempted the steps."
Task 2
Apply an "out" to prevent fabrications (hallucinations) when the AI doesn't know the answer.
Solution:
Add the explicit instruction: "If you do not know the answer based on the provided text or standard curriculum, state clearly that you do not know."